<style scoped>
</style>
<template>
  <template v-if="page_back_list">
    <PageBlock v-for="row in page_back_list" v-bind="row"></PageBlock>
  </template>
  <component v-else-if="template && model && this_action" :is="template" :model="model" :this_action="this_action" />
</template>

<script>
import list_common from '@/components/model_base/list_common.vue'
import list_order_buy from '@/components/model_base/list_order_buy.vue'
import list_order from '@/components/model_base/list_order.vue'
import {S94Model} from "@/js/S94Model.js";
import {_get, href_handle} from "@/vue_plugin/router_auto.js";
import {toast} from "@/js/vant_tool.js";
import {use_config_map} from "@/store/config_map.js";
import PageBlock from "@/components/auto_import/PageBlock.vue";

export default {
  components: {PageBlock, list_common, list_order, list_order_buy},
  data(){
    return {
      model_name: _get('model_name'),
      action: _get('action',''),
      model: undefined,
      this_action: undefined,
      template: '',
    }
  },
  methods:{},
  computed:{
    page_back_list(){
      if (!this.this_action?.page_id) return null;
      let page = use_config_map().page_map[this.this_action.page_id];
      if (!page) return null;
      return JSON.parse(page.config_json);
    }
  },
  mounted(){
    let model = S94Model.find(this.model_name);
    if (!model) {
      toast(`参数错误：model_name=${this.model_name}`);
      return href_handle(-1, 1500);
    }
    let this_action = model.findActionHome(this.action, 'list');
    if (!this_action) {
      toast(`参数错误：action=${this.action}`);
      return href_handle(-1, 1500);
    }
    // 模板
    let def_template = model.switch_pay ? 'list_order' : 'list_common';
    this.template = this_action.template || this_action.config.template || def_template;
    this.model = model;
    this.this_action = this_action;
  }
}
</script>